package cn.schoolwow.util.test.module.crypto.testcase;

import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;
import cn.schoolwow.util.domain.crypto.cipher.rsa.RSACipher;
import cn.schoolwow.util.domain.crypto.cipher.rsa.RSAKeyPairType;
import org.junit.Assert;

import java.security.KeyPair;

public class RSATestCaseFlow implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        String message = "hello,world!";

        KeyPair keyPair = RSACipher.generateKeyPair(RSAKeyPairType.Key2048);
        RSACipher rsaCipher = RSACipher.newCipher()
                .data(message)
                .keyPair(keyPair);
        String encryptText = rsaCipher.encrypt();
        String plainText = rsaCipher.data(encryptText).decrypt();
        Assert.assertEquals(message, plainText);
    }

    @Override
    public String name() {
        return "RSA算法测试用例";
    }
}
